const mysql = require('mysql');
const { dbConfig } = require('../../config');
const pool = mysql.createPool(dbConfig);

const db = {};

db.query = function (sql, params) {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, connection) => {
            if (err) return reject(err);
            connection.query(sql, params, (error, results, fields) => {
                connection.release();
                if (error) return reject(error);
                resolve(results);
            })
        })
    })
}
module.exports = db;